// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyExportDBAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>
#include "PyDBOptionsAttributes_Helpers.h"
#include <PyDBOptionsAttributes.h>

// ****************************************************************************
// Module: PyExportDBAttributes
//
// Purpose:
//   The attributes for export a database
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a ExportDBAttributes.
//
struct ExportDBAttributesObject
{
    PyObject_HEAD
    ExportDBAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewExportDBAttributes(int);


// ****************************************************************************
// Module: PyExportDBAttributes_ToString
//
// Purpose: 
//   Custom to string method. Custom b/c of handled for opts dict.
//
//
//  Programmer: Cyrus Harrison
//  Creation:   Mon May 11 14:14:38 PDT 2020
//
// ****************************************************************************
std::string
PyExportDBAttributes_ToString(const ExportDBAttributes *atts, const char *prefix, const bool /* forLogging */)
{
    std::string str;
    char tmpStr[1000];

    if(atts->GetAllTimes())
        snprintf(tmpStr, 1000, "%sallTimes = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sallTimes = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sdirname = \"%s\"\n", prefix, atts->GetDirname().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sfilename = \"%s\"\n", prefix, atts->GetFilename().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%stimeStateFormat = \"%s\"\n", prefix, atts->GetTimeStateFormat().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sdb_type = \"%s\"\n", prefix, atts->GetDb_type().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sdb_type_fullname = \"%s\"\n", prefix, atts->GetDb_type_fullname().c_str());
    str += tmpStr;
    {   const stringVector &variables = atts->GetVariables();
        snprintf(tmpStr, 1000, "%svariables = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < variables.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", variables[i].c_str());
            str += tmpStr;
            if(i < variables.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    if(atts->GetWriteUsingGroups())
        snprintf(tmpStr, 1000, "%swriteUsingGroups = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%swriteUsingGroups = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sgroupSize = %d\n", prefix, atts->GetGroupSize());
    str += tmpStr;

    std::string db_opts_dict_str = PyDBOptionsAttributes_CreateDictionaryStringFromDBOptions(atts->GetOpts(), false);
    if((!db_opts_dict_str.empty()) && // make sure its not an empty string
       (db_opts_dict_str.find("{}") != 0) ) // and not an empty dict
    {
        str += "DBExportOpts = ";
        str += db_opts_dict_str;
        str += "\n";
    }

    return str;
}

static PyObject *
ExportDBAttributes_Notify(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExportDBAttributes_SetAllTimes(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the allTimes in the object.
    obj->data->SetAllTimes(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExportDBAttributes_GetAllTimes(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetAllTimes()?1L:0L);
    return retval;
}

/*static*/ PyObject *
ExportDBAttributes_SetDirname(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the dirname in the object.
    obj->data->SetDirname(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExportDBAttributes_GetDirname(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetDirname().c_str());
    return retval;
}

/*static*/ PyObject *
ExportDBAttributes_SetFilename(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the filename in the object.
    obj->data->SetFilename(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExportDBAttributes_GetFilename(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetFilename().c_str());
    return retval;
}

/*static*/ PyObject *
ExportDBAttributes_SetTimeStateFormat(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the timeStateFormat in the object.
    obj->data->SetTimeStateFormat(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExportDBAttributes_GetTimeStateFormat(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetTimeStateFormat().c_str());
    return retval;
}

/*static*/ PyObject *
ExportDBAttributes_SetDb_type(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the db_type in the object.
    obj->data->SetDb_type(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExportDBAttributes_GetDb_type(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetDb_type().c_str());
    return retval;
}

/*static*/ PyObject *
ExportDBAttributes_SetDb_type_fullname(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the db_type_fullname in the object.
    obj->data->SetDb_type_fullname(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExportDBAttributes_GetDb_type_fullname(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetDb_type_fullname().c_str());
    return retval;
}

/*static*/ PyObject *
ExportDBAttributes_SetVariables(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetVariables() = vec;
    // Mark the variables in the object as modified.
    obj->data->SelectVariables();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExportDBAttributes_GetVariables(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the variables.
    const stringVector &variables = obj->data->GetVariables();
    PyObject *retval = PyTuple_New(variables.size());
    for(size_t i = 0; i < variables.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(variables[i].c_str()));
    return retval;
}

/*static*/ PyObject *
ExportDBAttributes_SetWriteUsingGroups(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the writeUsingGroups in the object.
    obj->data->SetWriteUsingGroups(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExportDBAttributes_GetWriteUsingGroups(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetWriteUsingGroups()?1L:0L);
    return retval;
}

/*static*/ PyObject *
ExportDBAttributes_SetGroupSize(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the groupSize in the object.
    obj->data->SetGroupSize(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExportDBAttributes_GetGroupSize(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetGroupSize()));
    return retval;
}

/*static*/ PyObject *
ExportDBAttributes_SetOpts(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;

    PyObject *newValue = NULL;
    if(!PyArg_ParseTuple(args, "O", &newValue))
        return NULL;
    if(!PyDBOptionsAttributes_Check(newValue))
        return PyErr_Format(PyExc_TypeError, "Field opts can be set only with DBOptionsAttributes objects");

    obj->data->SetOpts(*PyDBOptionsAttributes_FromPyObject(newValue));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExportDBAttributes_GetOpts(PyObject *self, PyObject *args)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)self;
    // Since the new object will point to data owned by this object,
    // we need to increment the reference count.
    Py_INCREF(self);

    PyObject *retval = PyDBOptionsAttributes_Wrap(&obj->data->GetOpts());
    // Set the object's parent so the reference to the parent can be decref'd
    // when the child goes out of scope.
    PyDBOptionsAttributes_SetParent(retval, self);

    return retval;
}



PyMethodDef PyExportDBAttributes_methods[EXPORTDBATTRIBUTES_NMETH] = {
    {"Notify", ExportDBAttributes_Notify, METH_VARARGS},
    {"SetAllTimes", ExportDBAttributes_SetAllTimes, METH_VARARGS},
    {"GetAllTimes", ExportDBAttributes_GetAllTimes, METH_VARARGS},
    {"SetDirname", ExportDBAttributes_SetDirname, METH_VARARGS},
    {"GetDirname", ExportDBAttributes_GetDirname, METH_VARARGS},
    {"SetFilename", ExportDBAttributes_SetFilename, METH_VARARGS},
    {"GetFilename", ExportDBAttributes_GetFilename, METH_VARARGS},
    {"SetTimeStateFormat", ExportDBAttributes_SetTimeStateFormat, METH_VARARGS},
    {"GetTimeStateFormat", ExportDBAttributes_GetTimeStateFormat, METH_VARARGS},
    {"SetDb_type", ExportDBAttributes_SetDb_type, METH_VARARGS},
    {"GetDb_type", ExportDBAttributes_GetDb_type, METH_VARARGS},
    {"SetDb_type_fullname", ExportDBAttributes_SetDb_type_fullname, METH_VARARGS},
    {"GetDb_type_fullname", ExportDBAttributes_GetDb_type_fullname, METH_VARARGS},
    {"SetVariables", ExportDBAttributes_SetVariables, METH_VARARGS},
    {"GetVariables", ExportDBAttributes_GetVariables, METH_VARARGS},
    {"SetWriteUsingGroups", ExportDBAttributes_SetWriteUsingGroups, METH_VARARGS},
    {"GetWriteUsingGroups", ExportDBAttributes_GetWriteUsingGroups, METH_VARARGS},
    {"SetGroupSize", ExportDBAttributes_SetGroupSize, METH_VARARGS},
    {"GetGroupSize", ExportDBAttributes_GetGroupSize, METH_VARARGS},
    {"SetOpts", ExportDBAttributes_SetOpts, METH_VARARGS},
    {"GetOpts", ExportDBAttributes_GetOpts, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
ExportDBAttributes_dealloc(PyObject *v)
{
   ExportDBAttributesObject *obj = (ExportDBAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *ExportDBAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyExportDBAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "allTimes") == 0)
        return ExportDBAttributes_GetAllTimes(self, NULL);
    if(strcmp(name, "dirname") == 0)
        return ExportDBAttributes_GetDirname(self, NULL);
    if(strcmp(name, "filename") == 0)
        return ExportDBAttributes_GetFilename(self, NULL);
    if(strcmp(name, "timeStateFormat") == 0)
        return ExportDBAttributes_GetTimeStateFormat(self, NULL);
    if(strcmp(name, "db_type") == 0)
        return ExportDBAttributes_GetDb_type(self, NULL);
    if(strcmp(name, "db_type_fullname") == 0)
        return ExportDBAttributes_GetDb_type_fullname(self, NULL);
    if(strcmp(name, "variables") == 0)
        return ExportDBAttributes_GetVariables(self, NULL);
    if(strcmp(name, "writeUsingGroups") == 0)
        return ExportDBAttributes_GetWriteUsingGroups(self, NULL);
    if(strcmp(name, "groupSize") == 0)
        return ExportDBAttributes_GetGroupSize(self, NULL);
    if(strcmp(name, "opts") == 0)
        return ExportDBAttributes_GetOpts(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyExportDBAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyExportDBAttributes_methods[i].ml_name),
                PyString_FromString(PyExportDBAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyExportDBAttributes_methods, self, name);
}

int
PyExportDBAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "allTimes") == 0)
        obj = ExportDBAttributes_SetAllTimes(self, args);
    else if(strcmp(name, "dirname") == 0)
        obj = ExportDBAttributes_SetDirname(self, args);
    else if(strcmp(name, "filename") == 0)
        obj = ExportDBAttributes_SetFilename(self, args);
    else if(strcmp(name, "timeStateFormat") == 0)
        obj = ExportDBAttributes_SetTimeStateFormat(self, args);
    else if(strcmp(name, "db_type") == 0)
        obj = ExportDBAttributes_SetDb_type(self, args);
    else if(strcmp(name, "db_type_fullname") == 0)
        obj = ExportDBAttributes_SetDb_type_fullname(self, args);
    else if(strcmp(name, "variables") == 0)
        obj = ExportDBAttributes_SetVariables(self, args);
    else if(strcmp(name, "writeUsingGroups") == 0)
        obj = ExportDBAttributes_SetWriteUsingGroups(self, args);
    else if(strcmp(name, "groupSize") == 0)
        obj = ExportDBAttributes_SetGroupSize(self, args);
    else if(strcmp(name, "opts") == 0)
        obj = ExportDBAttributes_SetOpts(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
ExportDBAttributes_print(PyObject *v, FILE *fp, int flags)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)v;
    fprintf(fp, "%s", PyExportDBAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
ExportDBAttributes_str(PyObject *v)
{
    ExportDBAttributesObject *obj = (ExportDBAttributesObject *)v;
    return PyString_FromString(PyExportDBAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *ExportDBAttributes_Purpose = "The attributes for export a database";
#else
static char *ExportDBAttributes_Purpose = "The attributes for export a database";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(ExportDBAttributesType,         \
                  "ExportDBAttributes",           \
                  ExportDBAttributesObject,       \
                  ExportDBAttributes_dealloc,     \
                  ExportDBAttributes_print,       \
                  PyExportDBAttributes_getattr,   \
                  PyExportDBAttributes_setattr,   \
                  ExportDBAttributes_str,         \
                  ExportDBAttributes_Purpose,     \
                  ExportDBAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
ExportDBAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &ExportDBAttributesType
         || Py_TYPE(other) != &ExportDBAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    ExportDBAttributes *a = ((ExportDBAttributesObject *)self)->data;
    ExportDBAttributes *b = ((ExportDBAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static ExportDBAttributes *defaultAtts = 0;
static ExportDBAttributes *currentAtts = 0;

static PyObject *
NewExportDBAttributes(int useCurrent)
{
    ExportDBAttributesObject *newObject;
    newObject = PyObject_NEW(ExportDBAttributesObject, &ExportDBAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new ExportDBAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new ExportDBAttributes(*defaultAtts);
    else
        newObject->data = new ExportDBAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapExportDBAttributes(const ExportDBAttributes *attr)
{
    ExportDBAttributesObject *newObject;
    newObject = PyObject_NEW(ExportDBAttributesObject, &ExportDBAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (ExportDBAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
ExportDBAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewExportDBAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef ExportDBAttributesMethods[] = {
    {"ExportDBAttributes", ExportDBAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *ExportDBAttributesObserver = 0;

std::string
PyExportDBAttributes_GetLogString()
{
    std::string s("ExportDBAtts = ExportDBAttributes()\n");
    if(currentAtts != 0)
        s += PyExportDBAttributes_ToString(currentAtts, "ExportDBAtts.", true);
    return s;
}

static void
PyExportDBAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("ExportDBAtts = ExportDBAttributes()\n");
        s += PyExportDBAttributes_ToString(currentAtts, "ExportDBAtts.", true);
        cb(s);
    }
}

void
PyExportDBAttributes_StartUp(ExportDBAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyExportDBAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(ExportDBAttributesObserver == 0)
    {
        ExportDBAttributesObserver = new ObserverToCallback(subj,
            PyExportDBAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyExportDBAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete ExportDBAttributesObserver;
    ExportDBAttributesObserver = 0;
}

PyMethodDef *
PyExportDBAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return ExportDBAttributesMethods;
}

bool
PyExportDBAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &ExportDBAttributesType);
}

ExportDBAttributes *
PyExportDBAttributes_FromPyObject(PyObject *obj)
{
    ExportDBAttributesObject *obj2 = (ExportDBAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyExportDBAttributes_New()
{
    return NewExportDBAttributes(0);
}

PyObject *
PyExportDBAttributes_Wrap(const ExportDBAttributes *attr)
{
    return WrapExportDBAttributes(attr);
}

void
PyExportDBAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    ExportDBAttributesObject *obj2 = (ExportDBAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyExportDBAttributes_SetDefaults(const ExportDBAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new ExportDBAttributes(*atts);
}

